#include "QWidgetProperty.h"


#include "private/QWidgetProperty_p.h"

using namespace QPE;




QWidgetProperty::QWidgetProperty(const QString& name, QWidget* widget)
	: QEmptyProperty(new QWidgetPropertyPrivate(name, QVariant::Invalid, widget))
{
}

QWidgetProperty::~QWidgetProperty()
{
	//
}

QWidget *QWidgetProperty::getWidget() const
{
	return static_cast<QWidgetPropertyPrivate*>(d_ptr)->Widget.data();
}

void QWidgetProperty::setWidget(QWidget* widget)
{
	QWidgetPropertyPrivate* tmpDPtr = static_cast<QWidgetPropertyPrivate*>(d_ptr);
	QWidget* tmpOldWidget = tmpDPtr->Widget.data();
	if(tmpOldWidget)
		tmpOldWidget->deleteLater();

	tmpDPtr->Widget = widget;
}


QString QWidgetProperty::type() const
{
	return "widget";
}

QProperty* QWidgetProperty::clone(bool include_children, QProperty* container) const
{
	// todo: This is a tricky one to clone... don't know what would be the best way to do so... Maybe serialize the widget somehow?
	return QProperty::clone(include_children, container ? container : new QWidgetProperty(getName()));
}
